package com.lanhu.designpattern.proxy.dynamicproxy.jdkproxy;

import sun.misc.ProxyGenerator;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author 蓝狐
 */
public class Test {
    public static void main (String[] args) {
        Person object = (Person) new HouseAgent().getInstance(new Tenant("蓝狐"));
        //此处断点会发现一个proxy0的文件
        object.findWarehouse();

            byte[] bytes = ProxyGenerator.generateProxyClass("$proxy0", new Class[]{Person.class});
        FileOutputStream fileOutputStream = null;
        try {
            fileOutputStream = new FileOutputStream("E://$proxy0.class");
            fileOutputStream.write(bytes);
            fileOutputStream.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
